package com.bank.lenovoz5;

import android.content.Context;
import android.os.RemoteException;
import android.support.test.InstrumentationRegistry;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiSelector;
import android.text.TextUtils;
import android.util.Log;

import com.receive.SMSReceiverSend;
import com.show.api.util.StringUtils;
import com.utils.ChatClient;
import com.utils.Constants;
import com.utils.FileHelper;
import com.utils.LogToFile;
import com.utils.Util;

import java.text.DecimalFormat;
import java.util.List;

import static android.os.SystemClock.sleep;
import static com.bank.PAbank.isNumeric;
import static com.utils.ChatClient.CCBMethodName;
import static com.utils.ChatClient.CODE_TIMER;
import static com.utils.ChatClient.C_updateBalance_W;
import static com.utils.ChatClient.ConfirmOrder;
import static com.utils.ChatClient.PAUSE;
import static com.utils.ChatClient.S_paused_C;
import static com.utils.ChatClient.addWorkTime;
import static com.utils.ChatClient.getSerialNumber;
import static com.utils.ChatClient.getmap;
import static com.utils.ChatClient.list;
import static com.utils.ChatClient.mapDelete;
import static com.utils.ChatClient.setDevicesLog;
import static com.utils.ChatClient.user;
import static com.utils.Constants.orderBankName;
import static com.utils.UIUtils.showLog;

/**
 * 描述：平安银行自动化脚本
 * 时间：Created by Administrator on 2017/4/13.
 */
public class Z5PAbank {
    private static String BANK_NAME = "平安银行";
    private static String BANK_FLAG = "PA";
    private UiDevice mDevice;
    private Context context = InstrumentationRegistry.getTargetContext();
    private static String tableType = "abc";
    private static String sumMoney = "-1";
    // 默认分辨率 1080*1920
    // 键盘字母和数字切换
    private static int[] tableAbc123;
    private static int[] tableAbc123_2016 = {180, 2020};


    private static int[][] xy_123;
    private static int[][] xy_123_2016 = new int[][]{
            {170, 1535}, {530, 1535}, {890, 1535},
            {170, 1700}, {530, 1700}, {890, 1700},
            {170, 1855}, {530, 1855}, {890, 1855},
            {530, 2015}};


    private static int[][] xy_abc;

    private static int[][] xy_abc_2016 = new int[][]{
            {60, 1560}, {160, 1560}, {270, 1560}, {370, 1560}, {480, 1560}, {590, 1560}, {700, 1560}, {800, 1560}, {910, 1560}, {1010, 1560},
            {120, 1700}, {220, 1700}, {320, 1700}, {430, 1700}, {540, 1700}, {650, 1700}, {750, 1700}, {850, 1700}, {960, 1700},
            {220, 1860}, {320, 1860}, {430, 1860}, {540, 1860}, {650, 1860}, {750, 1860}, {850, 1860}};

    //金额
    private static int[][] xy_num_m;
    private static int[][] xy_num_m_2016 = new int[][]{
            {170, 1535}, {530, 1535}, {890, 1535},
            {170, 1700}, {530, 1700}, {890, 1700},
            {170, 1855}, {530, 1855}, {890, 1855},
            {170, 2015}, {530, 2015}};

    //键盘适配
    private void keyPhone() {
        xy_123 = xy_123_2016;
        xy_abc = xy_abc_2016;
        xy_num_m = xy_num_m_2016;
        tableAbc123 = tableAbc123_2016;
    }

    public Z5PAbank(UiDevice mDevice) throws UiObjectNotFoundException {
        this.mDevice = mDevice;
        keyPhone();
        info();
    }


    /**
     * @throws UiObjectNotFoundException 异常捕获
     */
    public void info() throws UiObjectNotFoundException {
        sleep(ChatClient.overtime_5);
        //检查usb连接状态
        while (true) {
            if (Constants.STATE_USB) {
                transfer();
                break;
            } else {
                showMsg("USB链接错误");
            }
        }
    }


    //检索转账：进入转账
    public void transfer() throws UiObjectNotFoundException {
        //获取页面上登录节点
        long flagTime = ChatClient.overtime_8;
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            long nowtime = System.currentTimeMillis();
            if ((nowtime - ChatClient.begintime) > flagTime) {
                LogToFile.d("====提示弹窗===", ">>>>>提示弹窗处理完成");
                break;
            }
            UiObject home_dialog = mDevice.findObject(new UiSelector().resourceId("com.pingan.paces.ccms:id/btn_left").text
                    ("取消"));
            if (home_dialog != null && home_dialog.exists()) {
                LogToFile.d("====弹出提示弹窗===", ">>>>>弹出提示弹窗关闭");
                home_dialog.click();
                flagTime += ChatClient.overtime_3;
            }
            UiObject home_dialog1 = mDevice.findObject(new UiSelector().resourceId("com.pingan.paces.ccms:id/rl_close_background"));
            if (home_dialog1 != null && home_dialog1.exists()) {
                showMsg(">>>>>弹出提示弹窗关闭1");
                home_dialog1.click();
                flagTime += ChatClient.overtime_3;
            }
            UiObject home_wifi = mDevice.findObject(new UiSelector().resourceId("com.pingan.paces.ccms:id/close_wifi"));
            if (home_wifi != null && home_wifi.exists()) {
                LogToFile.d("====弹出免流量升级弹窗===", ">>>>>关闭免流量升级弹窗");
                home_wifi.click();
                flagTime += ChatClient.overtime_3;
            }
            UiObject home_pop = mDevice.findObject(new UiSelector().resourceId("com.pingan.paces.ccms:id/ad_popupwindow"));
            if (home_pop != null && home_pop.exists()) {
                LogToFile.d("====弹出广告===", ">>>>>弹出广告");
                UiObject close_pop = home_pop.getChild(new UiSelector().className("android.widget.ImageView").index(0));
                if (close_pop.exists()) {
                    LogToFile.d("====弹出广告层关闭===", ">>>>>弹出广告层关闭");
                    close_pop.click();
                    flagTime += ChatClient.overtime_3;
                }
            }
            showMsg("等待广告...");
            sleep(1000);
        }

        sleep(3000);
        while (true) {
            UiObject transfer1 = mDevice.findObject(new UiSelector().resourceId("com.pingan.paces.ccms:id/item_label").index(5));
            if (!transfer1.exists()) {
                transfer1 = mDevice.findObject(new UiSelector().resourceId("com.pingan.paces.ccms:id/tv_native_title").text("转账"));
            }
            UiObject transfer3 = mDevice.findObject(new UiSelector().resourceId("com.pingan.paces.ccms:id/tv_first").index(0));
            UiObject transfer2 = mDevice.findObject(new UiSelector().resourceId("com.pingan.paces.ccms:id/tv_native_title")
                    .descriptionContains("转账"));
            if (transfer1.exists()) {
                transfer1.click();
                Login();
                break;
            } else if (transfer2.exists()) {
                transfer2.click();
                Login();
                break;
            } else if (transfer3.exists()) {
                transfer3.click();
                Login();
                break;
            }
        }
    }

    /**
     * 进入登录页面补充用户信息
     */
    public void Login() {
        CCBMethodName = "Login";
        sleep(2000);
        ChatClient.addWorkTime(ChatClient.overtime_30);
        try {
            while (true) {
                sleep(1000);
                UiObject pwd1 = mDevice.findObject(new UiSelector().className("android.view.View").text("登录密码"));
                UiObject pwd2 = mDevice.findObject(new UiSelector().className("android.view.View").descriptionContains("登录密码"));
                if (pwd1.exists()) {
                    LogToFile.d("====点击密码输入===", ">>>>>点击密码输入1");
                    pwd1.click();
                    sleep(2000);
                    //截取键盘模拟用户输入登录密码
                    if (user.getPwd() != null) {
                        tableType = "abc";
                        setClick(user.getPwd());
                    }
                    break;
                } else if (pwd2.exists()) {
                    LogToFile.d("====点击密码输入===", ">>>>>点击密码输入2");
                    pwd2.click();
                    sleep(2000);
                    //截取键盘模拟用户输入登录密码
                    if (user.getPwd() != null) {
                        tableType = "abc";
                        setClick(user.getPwd());
                    }
                    break;
                }
            }
            // 点击空白关闭键盘
            mDevice.click(50, 300);
            sleep(ChatClient.overtime_1);
            //            while (true) {
            //                UiObject mCB = mDevice.findObject(new UiSelector().resourceId("changeCheckItem"));
            //                if (mCB.exists()) {
            //                    showMsg("勾选用户条款...");
            //                    mCB.click();
            //                    sleep(ChatClient.overtime_1);
            //                    break;
            //                }
            //            }

            while (true) {
                UiObject login;
                login = mDevice.findObject(new UiSelector().resourceId("submit"));
                if (login.exists()) {
                    LogToFile.d("====点击登录按钮===", ">>>>>点击登录按钮");
                    login.click();
                    break;
                }
            }
            sleep(ChatClient.overtime_3);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                long nowtime = System.currentTimeMillis();
                if ((nowtime - ChatClient.begintime) > ChatClient.overtime_10) {
                    break;
                }
                UiObject ssmm1 = mDevice.findObject(new UiSelector().text("跳过").className("android.widget.TextView"));
                UiObject ssmm2 = mDevice.findObject(new UiSelector().descriptionContains("跳过").className("android.widget.TextView"));
                UiObject button1 = mDevice.findObject(new UiSelector().text("我知道了").className("android.widget.Button"));
                UiObject button2 = mDevice.findObject(new UiSelector().descriptionContains("我知道了").className("android.widget.Button"));
                if (ssmm1.exists()) {
                    ssmm1.click();
                    sleep(ChatClient.overtime_3);
                } else if (ssmm2.exists()) {
                    ssmm2.click();
                    sleep(ChatClient.overtime_3);
                } else if (button1.exists()) {
                    button1.click();
                    sleep(ChatClient.overtime_3);
                    break;
                } else if (button2.exists()) {
                    button2.click();
                    sleep(ChatClient.overtime_3);
                    break;
                }
            }

            //超时点击登录
            while (true) {
                long nowtime = System.currentTimeMillis();
                if ((nowtime - ChatClient.begintime) > ChatClient.overtimewait) {
                    // 直接坐标点击银行账号转账
                    mDevice.click(90, 280);
                    LogToFile.d("====银行账号转账===", ">>>>>超时点击登录");
                    break;
                }
                UiObject zhzz1 = mDevice.findObject(new UiSelector().text("银行账号转账").className("android.view.View"));
                UiObject zhzz2 = mDevice.findObject(new UiSelector().descriptionContains("银行账号转账").className("android.view.View"));
                if (zhzz1.exists() || zhzz2.exists()) {
                    LogToFile.d("===银行账号转账===", ">>>>>回到转账页面，登陆成功");
                    break;
                }
            }
            ChatClient.loginS();
            setRemittance();
        } catch (Exception e) {
            setDevicesLog(e.getMessage());
            e.printStackTrace();
        }
    }

    /**
     * 登录成功后进入转账
     */
    public void setRemittance() {
        LogToFile.d("===setRemittance===", ">>>>>Inter");
        try {
            sleep(ChatClient.overtime_1);
            CCBMethodName = "setTimerun";
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                long nowtime = System.currentTimeMillis();
                if ((nowtime - ChatClient.begintime) > ChatClient.overtime_5) {
                    LogToFile.d("====银行账号转账页===", ">>>>>未找到");
                    break;
                }
                UiObject zhzz1 = mDevice.findObject(new UiSelector().text("银行账号转账").className("android.view.View"));
                UiObject zhzz2 = mDevice.findObject(new UiSelector().descriptionContains("银行账号转账").className("android.view.View"));
                LogToFile.d("===setRemittance===", ">>>>>while");
                if (zhzz1.exists()) {
                    LogToFile.d("===银行账号转账===", ">>>>>跳转转账页面zhzz1");
                    zhzz1.click();
                    break;
                } else if (zhzz2.exists()) {
                    LogToFile.d("===银行账号转账===", ">>>>>跳转转账页面zhzz2");
                    zhzz2.click();
                    break;
                }
            }
            addWorkTime(ChatClient.overtime_30);
            handlePageStuck();
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                long nowtime = System.currentTimeMillis();
                if ((nowtime - ChatClient.begintime) > ChatClient.overtime_5) {
                    LogToFile.d("====银行账号转账页===", ">>>>>引导弹窗超时");
                    break;
                }
                UiObject mBT = mDevice.findObject(new UiSelector().descriptionContains("我知道了").className("android.widget.Button"));
                if (mBT.exists()) {
                    LogToFile.d("===银行账号转账页===", ">>>>>关闭引导弹窗");
                    mBT.click();
                    break;
                }
            }

            while (true) {
                UiObject nameInput = mDevice.findObject(new UiSelector().resourceId("nameInput"));
                Log.d("=====平安银行=====", "====查找收款人输入框====");
                if (nameInput.exists()) {
                    Log.d("=====平安银行=====", "====找到收款人输入框====");
                    break;
                }
            }

            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                long nowtime = System.currentTimeMillis();
                if ((nowtime - ChatClient.begintime) > 10000) {
                    break;
                }
                String sum = "";
                List<UiObject2> u2s = mDevice.findObjects(By.descContains("可用余额"));
                if (u2s.size() == 0) {
                    u2s = mDevice.findObjects(By.textContains("可用余额"));
                    if (u2s.size() > 0 && u2s.get(0) != null) {
                        sum = u2s.get(0).getText();
                    }
                } else {
                    if (u2s.get(0) != null) {
                        sum = u2s.get(0).getContentDescription();
                    }
                }

                if (!TextUtils.isEmpty(sum)) {
                    LogToFile.e("====test====", "sum = " + sum);
                    sum = sum.substring(sum.indexOf("：") + 1, sum.length() - 1);
                    LogToFile.e("====test====", "sum = " + sum);
                    sumMoney = sum.replace(",", "");
                    LogToFile.e("====test====", "sum = " + sum);
                    C_updateBalance_W(Double.parseDouble(sumMoney));
                    break;
                }
                sleep(1000);
            }
            while (true) {
                sleep(2000);
                if (ChatClient.existOrder()) {
                    orderBankName = Constants.getBank(list.get(0).getBankName(), "PA");
                    if (ConfirmOrder) {
                        //查账
                        showMsg("开始查账");
                        auditOrder();
                    } else {//转账
                        showMsg("开始转账");
                        remittanceLogin();
                    }
                } else {
                    if (PAUSE) {
                        showMsg("进入等待订单流程");
                        setTimerun();
                    } else {
                        S_paused_C();
                        sleep(1000);
                    }
                }
            }
        } catch (Exception e) {
            setDevicesLog(e.getMessage());
            e.printStackTrace();
        }

    }


    /**
     * 转账汇款
     */
    public void remittanceLogin() {
        try {
            CCBMethodName = "remittanceLongin";
            handlePageStuck();
            sleep(2000);
            while (true) {
                UiObject bankNo_ = mDevice.findObject(new UiSelector().resourceId("inputCardNum"));
                if (bankNo_.exists()) {
                    LogToFile.d("=====平安银行====", "=====填充银行卡号====");
                    bankNo_.setText(list.get(0).getBankNo());
                    sleep(1000);
                    mDevice.click(500, 320);
                    break;
                }
            }
            sleep(2000);
            getSumMoney(true);
            while (true) {
                UiObject nameInput = mDevice.findObject(new UiSelector().resourceId("nameInput"));
                if (nameInput.exists()) {
                    nameInput.click();
                    LogToFile.d("=====平安银行====", "=====填充姓名====");
                    nameInput.setText(list.get(0).getUserName());
                    sleep(1000);
                    mDevice.click(500, 320);
                    break;
                }
            }
            sleep(2000);
            clickMoney();
            sleep(2000);
            /*选择银行名*/
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                long nowtime = System.currentTimeMillis();
                if ((nowtime - ChatClient.begintime) > ChatClient.overtime_10) {
                    notBankName(false);
                    return;
                }
                UiObject mTV_bank_name_ = mDevice.findObject(new UiSelector().index(0).text("开户行"));
                if (mTV_bank_name_.exists()) {
                    UiObject mV_bank_name_search = mTV_bank_name_.getFromParent(new UiSelector().index(2).className("android.view.View"));
                    if (mV_bank_name_search.exists()) {
                        String text = mV_bank_name_search.getText();
                        showMsg("找到银行名---" + text);
                        if (text.contains("请选择")) {
                            LogToFile.d("=====平安银行====", "=====进入开户行选择页面====");
                            mV_bank_name_search.click();
                            sleep(ChatClient.overtime_5);
                            if (selectBankName()) {
                                showMsg("银行选择成功...");
                                break;
                            } else {
                                notBankName(true);
                                return;
                            }
                        } else {
                            showMsg("存在银行名...");
                            break;
                        }
                    }
                }
            }

            sleep(1000);
            sleep(3000);
            if (sumMoney.equals("")) {
                sumMoney = "-1";
            }
            LogToFile.d("====---moeny-====", "===moeny====:" + sumMoney);
            //账户余额是否大于转账金额
            if (Double.parseDouble(sumMoney) < Double.parseDouble(list.get(0).getMoney())) {
                failureToReport("账户余额不足", 1, 0);
                return;
            }
            mDevice.drag(100, 500, 200, 250, 20);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                long nowtime = System.currentTimeMillis();
                if ((nowtime - ChatClient.begintime) > 5000) {
                    mDevice.click(360, 1710);
                    break;
                }
                UiObject ok1 = mDevice.findObject(new UiSelector().text("下一步").className("android.widget.Button"));
                UiObject ok2 = mDevice.findObject(new UiSelector().descriptionContains("下一步").className("android.widget.Button"));
                if (ok1.exists()) {
                    LogToFile.d("====进入下一步流程===", ">>>>>进入下一步流程点击完成");
                    ok1.click();
                    CCBMethodName = "Submit";//提交
                    sleep(2000);
                    break;
                } else if (ok2.exists()) {
                    LogToFile.d("====进入下一步流程===", ">>>>>进入下一步流程点击完成");
                    ok2.click();
                    CCBMethodName = "Submit";//提交
                    sleep(2000);
                    break;
                }
            }
            LogToFile.d("====进入下一步流程==*****=", ">>>>>进入下一步流程点击完成");
            while (true) {
                sleep(2000);
                long nowtime = System.currentTimeMillis();
                if ((nowtime - ChatClient.begintime) > 10 * 1000) {
                    break;
                }
                LogToFile.d("==检测是否有错误弹框==", "=====检测是否有错误弹框====");
                UiObject view = mDevice.findObject(new UiSelector().className("android.view.View").resourceId("superTransfer"));
                UiObject view1 = view.getChild(new UiSelector().className("android.view.View").index(0));
                UiObject view2 = view1.getChild(new UiSelector().className("android.view.View").index(16));
                UiObject view3 = view2.getChild(new UiSelector().className("android.view.View").index(0));
                UiObject view4 = view3.getChild(new UiSelector().className("android.view.View").index(0));
                UiObject next = mDevice.findObject(new UiSelector().text("我知道了").className("android.widget.Button"));
                UiObject nextdesc = mDevice.findObject(new UiSelector().description("我知道了").className("android.widget.Button"));

                sleep(1000);
                if (next.exists()) {
                    String info = view4.getText();
                    LogToFile.d("==点击按钮取消弹框==", "=====点击按钮取消弹框====" + info);
                    next.click();
                    if (isCheckStr(info)) {
                        failureToReport(info, 0, 0);
                    } else {
                        failureToReport(info, 6, 0);
                    }
                    return;
                }
                if (nextdesc.exists()) {
                    List<UiObject2> u2s = mDevice.findObjects(By.clazz("android.webkit.WebView"));
                    List<UiObject2> u2ss = u2s.get(0).getChildren().get(0).getChildren();
                    String msg = u2ss.get(u2ss.size() - 2).getContentDescription();
                    LogToFile.d("==点击按钮取消弹框==", "=====点击按钮取消弹框====" + msg);
                    nextdesc.click();
                    if (isCheckStr(msg)) {
                        failureToReport(msg, 0, 0);
                    } else {
                        failureToReport(msg, 6, 0);
                    }
                    back();
                    sleep(3000);
                    setRemittance();
                }

            }
            //密码框弹起前
            CCBMethodName = "Re_pwd_S";
            sleep(1000);
            while (true) {
                UiObject next1 = mDevice.findObject(new UiSelector().text("继续转账").className("android.widget.Button"));
                UiObject next2 = mDevice.findObject(new UiSelector().descriptionContains("继续转账").className("android.widget.Button"));
                UiObject next3 = mDevice.findObject(new UiSelector().text("继续转账 ").className("android.widget.Button"));
                UiObject next4 = mDevice.findObject(new UiSelector().descriptionContains("继续转账 ").className("android.widget.Button"));
                UiObject SPwd1 = mDevice.findObject(new UiSelector().text("忘记密码?").className("android.view.View"));
                UiObject SPwd2 = mDevice.findObject(new UiSelector().descriptionContains("忘记密码?").className("android.view.View"));
                if (next1.exists()) {
                    next1.click();
                } else if (next2.exists()) {
                    next2.click();
                } else if (next3.exists()) {
                    next3.click();
                } else if (next4.exists()) {
                    next4.click();
                } else if (SPwd1.exists() || SPwd2.exists()) {
                    LogToFile.d("====进入输入密码流程===", ">>>>>进入输入密码流程");
                    sleep(1000);
                    setClickN(user.getBankpwd());
                    LogToFile.d("====输入密码流程完毕===", ">>>>>输入密码流程完毕");
                    //密码框弹起后
                    CCBMethodName = "Re_pwd_E";
                    break;
                }
            }

            //判断是否获取到短信
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                long nowtime = System.currentTimeMillis();
                if ((nowtime - ChatClient.begintime) > ChatClient.overtime) {
                    ChatClient.timer(LogToFile.getMethodName(), ChatClient.errorStr);
                    return;
                }
                UiObject text_code1 = mDevice.findObject(new UiSelector().text("收不到验证码?").className("android.view.View"));
                UiObject text_code2 = mDevice.findObject(new UiSelector().descriptionContains("收不到验证码?").className("android.view" +
                        ".View"));
                if (text_code1.exists() || text_code2.exists()) {
                    //短信验证码框弹起前
                    CCBMethodName = "Re_send_S";
                    LogToFile.d("====进入短信验证码输入流程===", ">>>>>进入短信验证码输入流程");
                    break;
                }
                UiObject mBT_next = mDevice.findObject(new UiSelector().text("继续转账").className("android.widget.Button"));
                UiObject mTV_resultPage = mDevice.findObject(new UiSelector().text("完成").className("android.widget.TextView"));
                if (mBT_next.exists() || mTV_resultPage.exists()) {
                    LogToFile.d("====无短信验证码验证环节====", ">>>>>无短信验证码验证环节，直接进入结果页");
                    ChatClient.msg("<YZF>{'header':'" + ChatClient.M_TRANSFERFINISH_P + "'}</YZF>");
                    Constants.CODE = "";
                    getUserInfo(sumMoney);
                    return;
                }
            }
            smsFlag = 1;
            //判断是否获取到短信
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                long nowtime = System.currentTimeMillis();
                if ((nowtime - ChatClient.begintime) > ChatClient.overtime) {
                    ChatClient.timer(LogToFile.getMethodName(), ChatClient.errorStr);
                    return;
                }
                String useType = user.getUseType();
                Constants.CODE = "";
                if (!useType.equals("1")) {
                    String msg = getMsgBySimulator();
                    if (!TextUtils.isEmpty(msg)) {
                        setClickN(msg);
                        if (!isMsgError()) {
                            //输入短信验证码
                            LogToFile.d("====短信验证码输入流程完成===", ">>>>>短信验证码输入流程完成");
                            CODE_TIMER = 0;
                            ChatClient.msg("<YZF>{'header':'" + ChatClient.M_TRANSFERFINISH_P + "'}</YZF>");
                            Constants.CODE = "";
                            getUserInfo(sumMoney);
                            break;
                        } else {
                            boolean b = reCovered();
                            if (!b) {//流程无法继续，清除订单，上报失败
                                mDevice.pressBack();
                                sleep(ChatClient.overtime_3);
                                while (true) {
                                    UiObject zhzz1 = mDevice.findObject(new UiSelector().text("银行账号转账").className("android.view.View"));
                                    UiObject zhzz2 = mDevice.findObject(new UiSelector().descriptionContains("银行账号转账").className("android.view" +
                                            ".View"));
                                    LogToFile.d("===setRemittance===", ">>>>>while");
                                    if (zhzz1.exists()) {
                                        LogToFile.d("===银行账号转账===", ">>>>>返回转账页面");
                                        zhzz1.click();
                                        break;
                                    } else if (zhzz2.exists()) {
                                        LogToFile.d("===银行账号转账===", ">>>>>返回转账页面");
                                        zhzz2.click();
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                    }
                } else {
                    getMsgByPhone();
                    setClickN(Constants.CODE);
                    //输入短信验证码
                    LogToFile.d("====短信验证码输入流程完成===", ">>>>>短信验证码输入流程完成");
                    CODE_TIMER = 0;
                    ChatClient.msg("<YZF>{'header':'" + ChatClient.M_TRANSFERFINISH_P + "'}</YZF>");
                    Constants.CODE = "";
                    getUserInfo(sumMoney);
                    break;
                }
            }
        } catch (Exception e) {
            setDevicesLog(e.getMessage());
            e.printStackTrace();
        }
    }

    private boolean selectBankName() throws UiObjectNotFoundException {
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            long nowtime = System.currentTimeMillis();
            if ((nowtime - ChatClient.begintime) > ChatClient.overtime_5) {
                return false;
            }
            UiObject mET_bankName = mDevice.findObject(new UiSelector().resourceId("bankName"));
            if (mET_bankName.exists()) {
                mET_bankName.setText(list.get(0).getBankName());
                sleep(ChatClient.overtime_1);
                UiObject mTV_notBank = mDevice.findObject(new UiSelector().textContains("找不到"));
                if (mTV_notBank.exists()) {
                    showMsg("未找到银行...");
                    return false;
                }
                UiObject mV_bankName = mDevice.findObject(new UiSelector().text(orderBankName).className("android.view.View"));
                if (mV_bankName.exists()) {
                    showMsg("点击---" + orderBankName);
                    mV_bankName.click();
                    sleep(ChatClient.overtime_2);
                    return true;
                }
            }
        }
    }

    private void notBankName(boolean isBankSelectPage) throws UiObjectNotFoundException {
        failureToReport("银行名称错误", 1, 0);
        back();
        if (isBankSelectPage) {
            sleep(ChatClient.overtime_2);
            back();
        }
        sleep(ChatClient.overtime_2);
        while (true) {
            UiObject mTV = mDevice.findObject(new UiSelector().text("银行账号转账").className("android.view.View"));
            if (mTV.exists()) {
                LogToFile.d("=====平安银行====", "=====点击银行账号转账====");
                mTV.click();
                return;
            }
        }
    }

    private void clickMoney() throws UiObjectNotFoundException {
        while (true) {
            UiObject money1 = mDevice.findObject(new UiSelector().className("android.view.View").text("免手续费"));
            UiObject money2 = mDevice.findObject(new UiSelector().className("android.view.View").descriptionContains("免手续费"));
            if (money1.exists()) {
                money1.click();
                sleep(2000);
                LogToFile.d("=====平安银行====", "=====填充转账金额1====");
                setClickN(list.get(0).getMoney());
                mDevice.click(500, 320);
                sleep(1000);
                mDevice.click(500, 320);
                matchMoney();
                break;
            } else if (money2.exists()) {
                money2.click();
                sleep(2000);
                LogToFile.d("=====平安银行====", "=====填充转账金额2====");
                setClickN(list.get(0).getMoney());
                mDevice.click(500, 320);
                sleep(1000);
                mDevice.click(500, 320);
                matchMoney();
                break;
            }
        }
    }

    /**
     * 匹配输入金额
     *
     * @throws UiObjectNotFoundException 异常捕获
     */
    private void matchMoney() throws UiObjectNotFoundException {
        while (true) {
            UiObject mTV = mDevice.findObject(new UiSelector().text("转账金额").className("android.view.View"));
            if (mTV.exists()) {
                UiObject moneyParent = mTV.getFromParent(new UiSelector().className("android.view.View").index(1));
                if (moneyParent.exists()) {
                    UiObject mET_money = moneyParent.getChild(new UiSelector().className("android.view.View").index(0));
                    if (mET_money.exists()) {
                        String moneyText = mET_money.getText();
                        if (!StringUtils.isEmpty(moneyText)) {
                            String money = moneyText.replaceAll("元", "");
                            money = money.replaceAll(",", "");
                            if (money.equals("免手续费")) {
                                mET_money.click();
                                sleep(1000);
                                showMsg("无金额，排除00.00");
                                for (int i = 0; i < 5; i++) {
                                    mDevice.click(905, 2000);
                                    sleep(ChatClient.overtime_1);
                                }
                                mDevice.click(500, 320);
                                sleep(1000);
                                clickMoney();
                            } else if (Double.parseDouble(money) == Double.parseDouble(list.get(0).getMoney())) {
                                showMsg("输入金额匹配");
                                break;
                            } else {
                                showMsg("输入金额不匹配,重新输入");
                                mET_money.click();
                                sleep(1000);
                                for (int i = 0; i < moneyText.length() + 1; i++) {
                                    mDevice.click(905, 2015);
                                    sleep(ChatClient.overtime_1);
                                }
                                mDevice.click(500, 320);
                                sleep(1000);
                                mDevice.click(500, 320);
                                clickMoney();
                            }
                        }
                    }
                }
            }
        }
    }

    private int smsFlag = 1;

    /**
     * @return 是否以完成转账流程，true：完成（以走到结果页），false:未完成（界面超时，短信输入错误三次以上）
     * @throws UiObjectNotFoundException 异常捕获
     */
    private boolean reCovered() {
        smsFlag++;
        if (smsFlag > 3) {
            failureToReport("验证码错误超过3次", 1, 0);
            return false;
        }
        showMsg(">>>>>错误重新获取");
        ChatClient.addWorkTime(ChatClient.overtime_30);
        CCBMethodName = "Re_send_E";
        String useType = user.getUseType();
        sleep(ChatClient.overtime_1);
        for (int i = 0; i < 7; i++) {
            // 清楚输入的错误验证码
            mDevice.click(970, 2000);
            sleep(500);
        }
        Constants.CODE = "";
        if (!useType.equals("1")) {
            String msg = getMsgBySimulator();
            if (!TextUtils.isEmpty(msg)) {
                setClickN(msg);
                if (!isMsgError()) {
                    //输入短信验证码
                    LogToFile.d("====短信验证码输入流程完成===", ">>>>>短信验证码输入流程完成");
                    CODE_TIMER = 0;
                    ChatClient.msg("<YZF>{'header':'" + ChatClient.M_TRANSFERFINISH_P + "'}</YZF>");
                    Constants.CODE = "";
                    getUserInfo(sumMoney);
                } else {
                    return reCovered();
                }
            } else {
                return reCovered();
            }
        } else {
            getMsgByPhone();
            setClickN(Constants.CODE);
            //输入短信验证码
            LogToFile.d("====短信验证码输入流程完成===", ">>>>>短信验证码输入流程完成");
            CODE_TIMER = 0;
            ChatClient.msg("<YZF>{'header':'" + ChatClient.M_TRANSFERFINISH_P + "'}</YZF>");
            Constants.CODE = "";
            getUserInfo(sumMoney);
        }
        return true;
    }

    private boolean isMsgError() {
        ChatClient.begintime = System.currentTimeMillis();
        while (true) {
            sleep(1000);
            LogToFile.d("====短信验证码输入流程完成===", ">>>>>检测验证码是否正确");
            long nowTime = System.currentTimeMillis();
            if ((nowTime - ChatClient.begintime) > 5 * 1000) {
                return false;
            }
            List<UiObject2> u2s1 = mDevice.findObjects(By.descContains("验证码输入错误"));
            List<UiObject2> u2s2 = mDevice.findObjects(By.textContains("验证码输入错误"));
            if (u2s1.size() > 0 || u2s2.size() > 0) {
                LogToFile.d("====短信验证码输入流程完成===", ">>>>>检测验证码错误，重新获取");
                //                for (int i = 0; i < 6; i++) {
                //                    mDevice.click(675, 1400);
                //                    sleep(1000);
                //                }
                return true;
            }
        }
    }


    /**
     * 完成转账后回复服务端
     *
     * @param sumMoney1：余额
     */
    private void getUserInfo(String sumMoney1) {
        try {
            Exception exception = new Exception();
            StackTraceElement[] trace = exception.getStackTrace();
            String method = trace[0].getMethodName();
            sleep(2000);
            String type = "";
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            LogToFile.d("====进入转账完成流程===", ">>>>>进入转账完成流程");
            while (true) {
                long nowtime = System.currentTimeMillis();
                if ((nowtime - ChatClient.begintime) > ChatClient.overtime) {
                    ChatClient.timer(method, ChatClient.errorStr);
                    break;
                }
                UiObject state1 = mDevice.findObject(new UiSelector().text("转账提交成功").className("android.view.View"));
                UiObject state2 = mDevice.findObject(new UiSelector().descriptionContains("转账提交成功").className("android.view.View"));
                UiObject state3 = mDevice.findObject(new UiSelector().text("转账失败").className("android.view.View"));
                UiObject state4 = mDevice.findObject(new UiSelector().descriptionContains("转账失败").className("android.view.View"));
                UiObject state5 = mDevice.findObject(new UiSelector().text("处理中...").className("android.view.View"));
                UiObject state6 = mDevice.findObject(new UiSelector().descriptionContains("处理中").className("android.view.View"));
                if (state1.exists() || state2.exists() || state5.exists() || state6.exists()) {
                    sleep(2000);
                    if (state1.exists()) {
                        type = state1.getText();
                    } else if (state2.exists()) {
                        type = state2.getContentDescription();
                    } else if (state5.exists()) {
                        type = state5.getText();
                    } else if (state6.exists()) {
                        type = state6.getContentDescription();
                    }

                    if (Constants.getStr(type) == 0) {
                        DecimalFormat formater = new DecimalFormat("#0.##");
                        sumMoney = formater.format(Double.parseDouble(sumMoney1) - Double.parseDouble(list.get(0).getMoney()));
                        LogToFile.d("====sumMoney1===sumMoney==", sumMoney);
                        showMsg("本地保存余额");
                        String sumMoneyFile = user.getUserName() + BANK_FLAG + "_sumMoney.txt";
                        FileHelper.saveMoneySDFile(false, sumMoney, sumMoneyFile);
                        break;
                    } else {
                        sumMoney = sumMoney1;
                        LogToFile.d("====sumMoney1===sumMoney==", sumMoney);
                        break;
                    }
                } else if (state3.exists() || state4.exists()) {
                    LogToFile.d("====转账失败===", ">>>>>转账失败");
                    type = "转账失败";
                    break;
                }
            }
            LogToFile.d("====转账完成流程===", ">>>>>转账完成流程");
            type = type.replaceAll("\r|\n|\\s", "");
            failureToReport(type, Constants.getStr(type), 0);
            sleep(ChatClient.overtime_3);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            LogToFile.d("====检测转账完成页的信息===", ">>>>>检测转账完成页的信息");
            while (true) {
                long nowtime = System.currentTimeMillis();
                if ((nowtime - ChatClient.begintime) > ChatClient.overtime_20) {
                    LogToFile.d("====进入继续转账流程===", ">>>>>进入继续转账流程");
                    break;
                }
                UiObject seven1 = mDevice.findObject(new UiSelector().text("继续转账"));
                UiObject finish = mDevice.findObject(new UiSelector().text("取消").className("android.widget.Button"));
                UiObject finish1 = mDevice.findObject(new UiSelector().descriptionContains("取消").className("android.widget.Button"));
                if (seven1.exists()) {
                    LogToFile.d("====进入继续转账流程1===", ">>>>>进入继续转账流程1");
                    mDevice.click(100, 150);
                    mDevice.click(100, 150);
                    break;
                } else if (finish.exists()) {
                    LogToFile.d("====点击取消1===", ">>>>>点击取消1");
                    finish.click();
                } else if (finish1.exists()) {
                    LogToFile.d("====点击取消2===", ">>>>>点击取消2");
                    finish1.click();
                }
            }
            sleep(ChatClient.overtime_3);
            while (true) {
                UiObject mET_inputCardNum = mDevice.findObject(new UiSelector().resourceId("inputCardNum"));
                if (mET_inputCardNum.exists()) {
                    showMsg("以返回转账页");
                    mDevice.drag(20, 600, 20, 1300, 30);
                    break;
                }
            }
        } catch (Exception e) {
            setDevicesLog(e.getMessage());
            e.printStackTrace();
        }
    }


    /**
     * 查账
     *
     * @throws UiObjectNotFoundException 异常捕获
     */
    public void auditOrder() throws UiObjectNotFoundException, RemoteException {
        addWorkTime(ChatClient.overtime_60);
        handlePageStuck();
        getSumMoney(false); // 获取金额

        sleep(1000);

        back();// 返回

        sleep(2000);
        //进入转账记录
        while (true) {
            UiObject remittance1 = mDevice.findObject(new UiSelector().text("转账记录").className("android.view.View"));
            UiObject remittance2 = mDevice.findObject(new UiSelector().descriptionContains("转账记录").className("android.view.View"));
            if (remittance1.exists()) {
                CCBMethodName = "auditOrder";
                sleep(3000);
                remittance1.click();
                break;
            } else if (remittance2.exists()) {
                CCBMethodName = "auditOrder";
                sleep(3000);
                remittance2.click();
                break;
            }
        }
        showMsg("进入《转账交易记录》页1");
        //获取交易记录
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            long nowtime = System.currentTimeMillis();
            if ((nowtime - ChatClient.begintime) > 30000) {
                LogToFile.e("====平安查账====", "账单查找超时");
                failureToReport("查询超时", 1, 1);
                break;
            }
            LogToFile.e("====平安查账====", "账单查找...");
            sleep(2000);
            UiObject view = mDevice.findObject(new UiSelector().className("android.webkit.WebView").text("转账记录"));
            UiObject view0 = view.getChild(new UiSelector().className("android.view.View").index(0));
            UiObject viewChild = view0.getChild(new UiSelector().className("android.view.View").index(1));
            UiObject viewChild1 = viewChild.getChild(new UiSelector().className("android.view.View").index(1));
            UiObject view1;
            UiObject view2;
            UiObject view4;
            view1 = viewChild1.getChild(new UiSelector().className("android.view.View").index(1));
            view2 = viewChild1.getChild(new UiSelector().className("android.view.View").index(2));
            view4 = viewChild1.getChild(new UiSelector().className("android.view.View").index(4));
            if (view1.exists() && view2.exists() && view4.exists()) {
                LogToFile.d("=====平安查账界面=====", "查到条目...");
                String username = view1.getText();
                if (username.isEmpty()) {
                    username = view1.getContentDescription();
                }
                username = username.trim();
                String money = view2.getText();
                if (money.isEmpty()) {
                    money = view2.getContentDescription();
                }
                String status = view4.getText();
                if (status.isEmpty()) {
                    status = view4.getContentDescription();
                }
                String bankNo = "";
                if (!username.isEmpty()) {
                    bankNo = username.substring(username.length() - 5, username.length() - 1);
                }
                String moery1 = money.replaceAll("-", "");
                moery1 = Util.replaceMoney(moery1);
                showMsg("username：" + username + "---money：" + moery1 + "---bankNo:" + bankNo
                        .substring(bankNo.length() - 4, bankNo.length()) + "---status" + status);
                String bankNo1 = list.get(0).getBankNo();
                bankNo1 = bankNo1.substring(bankNo1.length() - 4, bankNo1.length());
                if (Double.parseDouble(list.get(0).getMoney()) == Double.parseDouble(moery1) && username.contains(list.get(0).getUserName())
                        && bankNo.equals(bankNo1) && status.contains("成功")) {
                    failureToReport("交易成功", 0, 1);
                } else {
                    String sumMoneyFile = user.getUserName() + BANK_FLAG + "_sumMoney.txt";
                    String oldMoney = FileHelper.readSDFile(sumMoneyFile);
                    switch (Constants.changeInAmount(BANK_NAME, oldMoney, sumMoney, list.get(0).getMoney())) {
                        case "0":
                            failureToReport("交易成功", 0, 1);
                            break;
                        case "1":
                            failureToReport("交易待处理...", 1, 1);
                            break;
                        case "4":
                            failureToReport("未查到条目", 4, 1);
                            break;
                    }
                }
                break;
            }
        }

        //返回
        back();
        while (true) {
            UiObject zhzz1 = mDevice.findObject(new UiSelector().text("银行账号转账").className("android.view.View"));
            UiObject zhzz2 = mDevice.findObject(new UiSelector().descriptionContains("银行账号转账").className("android.view.View"));
            if (zhzz1.exists()) {
                zhzz1.click();
                break;
            } else if (zhzz2.exists()) {
                zhzz2.click();
                break;
            }
        }

    }

    /**
     * 等待账单
     *
     * @throws UiObjectNotFoundException 异常捕获
     * @throws RemoteException           异常捕获
     */
    public void setTimerun() throws UiObjectNotFoundException, RemoteException {
        CCBMethodName = "setTimerun";

        handlePageStuck();
        getSumMoney(true); // 获取金额
        sleep(ChatClient.overtime_1);
        if (!ChatClient.waitExistOrder(ChatClient.overtime_60)) {
            back();// 返回
            sleep(ChatClient.overtime_2);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                sleep(ChatClient.overtime_1);
                UiObject zhzz1 = mDevice.findObject(new UiSelector().text("银行账号转账").className("android.view.View"));
                UiObject zhzz2 = mDevice.findObject(new UiSelector().descriptionContains("银行账号转账").className("android.view.View"));
                LogToFile.d("====检测银行账号转账===", ">>>>>检测银行账号转账");
                if (zhzz1.exists()) {
                    zhzz1.click();
                    break;
                } else if (zhzz2.exists()) {
                    zhzz2.click();
                    break;
                }
            }
        }
        Constants.CODE = "";
    }

    /**
     * 界面卡死转圈解决
     *
     * @throws RemoteException           异常捕获
     * @throws UiObjectNotFoundException 异常捕获
     */
    private void handlePageStuck() throws RemoteException, UiObjectNotFoundException {
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            long nowtime = System.currentTimeMillis();
            if ((nowtime - ChatClient.begintime) > ChatClient.overtime_20) {
                LogToFile.d("=====平安转账界面=====", "=====平安转账界面卡死点击运行应用键=====");
                mDevice.pressRecentApps();
                sleep(2000);
                while (true) {
                    UiObject mTV_app_name = mDevice.findObject(new UiSelector().resourceId("com.android.systemui:id/title").text
                            ("平安口袋银行"));
                    if (mTV_app_name.exists()) {
                        LogToFile.d("=====平安转账界面=====", "=====平安转账界面卡死点击底部从新打开平安银行=====");
                        mTV_app_name.click();
                        break;
                    }
                }
                sleep(2000);
            }
            UiObject nameInput = mDevice.findObject(new UiSelector().resourceId("nameInput"));
            if (nameInput.exists()) {
                break;
            }
        }
    }

    /**
     * 模拟点击密码
     *
     * @param pad_ 密码
     */
    public void setClick(String pad_) {
        try {
            char[] abc = "qwertyuiopasdfghjklzxcvbnm".toCharArray();//char数组
            char[] num = "1234567890".toCharArray();//char数组
            char[] pwd = pad_.toCharArray();//char数组
            char[] num_abc;//char数组
            for (int j = 0; j < pwd.length; j++) {
                if (isNumeric(String.valueOf(pwd[j]))) {
                    if (tableType.equals("abc")) {
                        mDevice.click(tableAbc123[0], tableAbc123[1]);
                        tableType = "123";
                        sleep(1000);
                    }
                    num_abc = num;
                } else {
                    if (tableType.equals("123")) {
                        mDevice.click(tableAbc123[0], tableAbc123[1]);
                        tableType = "abc";
                        sleep(1000);
                    }
                    num_abc = abc;
                }
                for (int i = 0; i < num_abc.length; i++) {
                    if (num_abc[i] == pwd[j]) {
                        if (isNumeric(String.valueOf(pwd[j]))) {
                            mDevice.click(xy_123[i][0], xy_123[i][1]);
                            sleep(1000);
                            Log.d("====---点击数字====" + pwd[j], xy_123[i][0] + "，" + xy_123[i][1]);
                        } else {
                            mDevice.click(xy_abc[i][0], xy_abc[i][1]);
                            sleep(1000);
                            Log.d("====---点击字母====" + pwd[j], xy_abc[i][0] + "，" + xy_abc[i][1]);
                        }
                        break;
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 模拟点击数字流程
     *
     * @param num 金额
     */
    public void setClickN(String num) {
        LogToFile.d("====进入点击数字流程===", ">>>>>进入点击数字流程");
        char[] n = "123456789.0".toCharArray();//char数组
        char[] jine = num.toCharArray();//char数组
        if (jine.length < 1) {
            return;
        }
        for (int j = 0; j < jine.length; j++) {
            for (int i = 0; i < n.length; i++) {
                if (n[i] == jine[j]) {
                    mDevice.click(xy_num_m[i][0], xy_num_m[i][1]);
                    showMsg("====点击数字====" + j);
                    sleep(1000);
                    break;
                }
            }
        }
    }

    /**
     * 检测银行卡和姓名是否匹配
     */
    private static boolean isCheckStr(String info) {
        boolean b = false;
        if (info.contains("请输入正确的收款人姓名") || info.contains("请选择所属银行") || info.contains("请选择支行名称")) {
            b = true;
        }
        return b;
    }

    //真机短信验证码
    private static void getMsgByPhone() {
        //判断是否获取到短信
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            long nowtime = System.currentTimeMillis();
            if ((nowtime - ChatClient.begintime) > ChatClient.overtime) {
                ChatClient.timer(LogToFile.getMethodName(), ChatClient.errorStr);
                return;
            }

            while (Constants.CODE.equals("")) {
                LogToFile.d("====收到短信验证码流程===", ">>>>>获取短信验证码");
                sleep(1000);
            }
            break;
        }
    }

    private String getMsgBySimulator() {
        if (smsFlag > 1) {
            sleep(ChatClient.overtime_1);
        } else {
            sleep(ChatClient.overtime_5);
        }
        ChatClient.requestSMSCode(user.getUserName(), user.getBankId());
        //判断是否获取到短信
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            sleep(1000);
            long nowtime = System.currentTimeMillis();
            if ((nowtime - ChatClient.begintime) > ChatClient.overtime) {
                ChatClient.timer(LogToFile.getMethodName(), ChatClient.errorStr);
                return "";
            }
            if (!TextUtils.isEmpty(ChatClient.smsCode.getSmscode()) && ChatClient.smsCode.getTelephone().equals(user.getUserName())) {
                showLog("收到短信验证码：" + ChatClient.smsCode.getSmscode());
                return ChatClient.smsCode.getSmscode();
            } else {
                String str = "未收到验证码，收到短信验证码手机号不匹配";
                showLog(str + ChatClient.smsCode.getTelephone());
                return "";
            }
        }
    }

    /**
     * 获取可用金额
     *
     * @param isSave 除查账外其他时间查账都要保存为保证余额的实时性 true:保存到本地 false：不保存
     */

    private void getSumMoney(boolean isSave) {
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            long nowtime = System.currentTimeMillis();
            if ((nowtime - ChatClient.begintime) > 10000) {
                break;
            }
            String sum = "";
            List<UiObject2> u2s = mDevice.findObjects(By.descContains("可用余额"));
            if (u2s.size() == 0) {
                u2s = mDevice.findObjects(By.textContains("可用余额"));
                if (u2s.size() > 0 && u2s.get(0) != null) {
                    sum = u2s.get(0).getText();
                }
            } else {
                if (u2s.get(0) != null) {
                    sum = u2s.get(0).getContentDescription();
                }
            }

            if (!TextUtils.isEmpty(sum)) {
                LogToFile.e("====test====", "sum = " + sum);
                sum = sum.substring(sum.indexOf("：") + 1, sum.length() - 1);
                LogToFile.e("====test====", "sum = " + sum);
                sumMoney = sum.replace(",", "");
                if (isSave) {
                    showMsg("本地保存余额");
                    String sumMoneyFile = user.getUserName() + BANK_FLAG + "_sumMoney.txt";
                    FileHelper.saveMoneySDFile(false, sumMoney, sumMoneyFile);
                }
                C_updateBalance_W(Double.parseDouble(sumMoney));
                break;
            }
            sleep(1000);
        }
    }

    /**
     * 返回
     */
    public void back() {
        mDevice.pressBack();
    }

    public void showMsg(String msg) {
        LogToFile.showLog(BANK_NAME, msg);
    }

    /**
     * @param info             上报内容
     * @param state            上报状态
     * @param auditAndTransfer 0为转账；1为查账
     */
    public static void failureToReport(String info, int state, int auditAndTransfer) {
        String mobileD = "'devices':'" + getSerialNumber() + "','prot':'" + Constants.PROT + "','phoneModel':'" + BANK_NAME +
                "'," + "'info':'" + info + "'";
        String json = "'order':'" + list.get(0).getOrder() + "','balance':'" + sumMoney + "','state':" + state + "," +
                "'type':1";
        showLog("mobileD = " + mobileD);
        showLog("json = " + json);
        String requestName;
        if (auditAndTransfer == 0) {
            requestName = ChatClient.M_SEND_TRADE_RESULT_P;
        } else {
            requestName = ChatClient.S_CONFIRM_TRADE_RESULT_C;
        }
        ChatClient.msg("<YZF>{'header':'" + requestName + "'," + json + "," + mobileD + "}</YZF>");
        //删除处理过的订单
        mapDelete(list.get(0).getOrder());
        getmap();
        sleep(ChatClient.overtime_2);
    }
}
